package com.fruit.web.vo.genl;

import java.util.List;




import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.fruit.service.IBrandService;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.web.bo.impl.Brand;
import com.fruit.web.constant.SpringBeanConstants;

@ManagedBean(name="existBrand")
@SessionScoped
public class ExistBrandBean implements java.io.Serializable {

	private SelectItem[] brandItems;

	public SelectItem[] getBrandItems() {
		return brandItems;
	}

	public void setBrandItems(SelectItem[] brandItems) {
		this.brandItems = brandItems;
	}
	public ExistBrandBean() {
		
		IBrandService<Brand,Long> brandService = (IBrandService<Brand,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.BRAND_SERVICE_BEAN_NAME);
		brandService.setEntityClass(Brand.class);
		brandService.setPKClass(Long.class);
		List<Brand> brands = brandService.getAll("serialNumber",true);
		SelectItem[] tempBrandItems = new SelectItem[brands.size()];
		if (null != brands && !(brands.isEmpty())) {
			for (int i=0; i< tempBrandItems.length; i++) {
				Brand brand = (Brand) brands.get(i);
				tempBrandItems[i] = new SelectItem(brand.getBrandCode(),brand.getBrandName());
			}
		}
		this.setBrandItems(tempBrandItems);
	}
}
